package com.unicomcz.query;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.unicomcz.ActionBase;

public class CardActiveAction extends ActionBase
{
    private List<CardActive> tc ;
    private int total=0;
    private String acctMonth;
    public List<CardActive> getTc()
    {
        return tc;
    }
    public void setTc(List<CardActive> tc)
    {
        this.tc = tc;
    }
    public String getAcctMonth()
    {
        return acctMonth;
    }
    public void setAcctMonth(String acctMonth)
    {
        this.acctMonth = acctMonth;
    }
    public String executeAction(){
        log = Logger.getLogger(this.getClass());  
        tc = new ArrayList<CardActive>();
        String sqlStr="SELECT brand,brand_sub,cnt FROM dls_card_cn";
        sqlStr += " where depart_id=? and acct_month=?";
        if (!query("dls",tc,sqlStr)) {
            //执行查询失败
            return "fail";
        }
        return SUCCESS;
    }
    protected void regQueryParam() throws Exception{
        if ((acctMonth==null)||(acctMonth.length()==0)) {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
            acctMonth=sf.format(new java.util.Date());
        }
        pstmt.setString(1, userInfo.getDepartCode());
        pstmt.setString(2, acctMonth);
    }
    protected void rs2List(ResultSet rs,List out) throws Exception{
        CardActive t = new CardActive();
        t.setBrand(rs.getString(1));
        t.setBrandSub(rs.getString(2));
        t.setCount(rs.getInt(3));
        total += rs.getInt(3);
        out.add(t);
    }
    protected void addTotal(List out) throws Exception{
        CardActive t = new CardActive();
        t.setBrand("");
        t.setBrandSub("合计");
        t.setCount(total);
    }

}
